import React from 'react';
import { useModel } from 'umi';

const OhterComp = () => {
  const { changeName } = useModel('globalData', res => ({
    changeName: res.setName,
  }));
  return (
    <button type="button" onClick={() => changeName('others name')}>
      change othes name
    </button>
  );
};

export default function ExampleWithUseModel() {
  const { name, setName } = useModel('globalData');

  return (
    <>
      <div>{name}</div>
      <button type="button" onClick={() => setName('new name')}>
        change name
      </button>
      <OhterComp />
    </>
  );
}
